﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;

namespace Utilities.DynamicValues
{
    public sealed class DynamicCompilationException : Exception
    {
        private readonly IEnumerable<CompilerError> m_CompilerErrors;

        public DynamicCompilationException(IEnumerable<CompilerError> compilerErrors)
            : base(String.Format("Compilation failed with errors:\n{0}", String.Join("\n", compilerErrors.Select(x => x.ErrorText).ToArray())))
        {
            m_CompilerErrors = compilerErrors;
        }

        public IEnumerable<CompilerError> CompilerErrors
        {
            get { return m_CompilerErrors; }
        }
    }
}